<?
/**
 * VoiceOne Settings/Contacts List
 *
 * Frontend to provide access to the contacts list system in voiceone.
 * @package voiceone
 * @subpackage  settings_extensions
 */

  include ("../../admin/config/cfg.php");
  global $cwlang,$cwUserId,$cwUserInfo;

  //================ PAGE LOGIC ================
  //build html for internal contacts (extensions)
  $html_int="";
  $count=0;
  $ret=$asterisk->getDirectory(0);
  if($err=$asterisk->getError()) die("Error: $err");
  if(is_array($ret)){
    $html_int.="<tr><td colspan=\"2\" class=\"todolisttitle\">".T_("Internal Contacts")."</td></tr>";
    $html_int.="<tr>";
    foreach($ret as $v) {
      $name=$v["name"];
      $username=$v["username"];
      $status=$v["status"];
      $domain=$soapHostname;
      if (strpos($status,"OK")!==false) $class="online";
      if (strpos($status,"UNKNOWN")!==false) $class="offline";
      if (strpos($status,"Unmonitored")!==false) $class="unknown";
      $html_int.="<td class=\"$class\"><img src=\"".$relBasePath."public/img/$class.gif\" alt=\"".$class."\"/> <a href=\"sip:$username@$domain\" title=\"$username\">$name</a></td>";
      if((++$count)%2==0) $html_int.="</tr><tr>\n";
    }
    if(($count!=0)&&(($count%2)!=0)) $html_int.="<td colspan=\"".($count%2)."\">&nbsp;</td>\n";
    $html_int.="</tr>";
  }

  //================ MAIN CONTENTS ================
  ob_start();
  ?>
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=T_("Contact List")?></h1>
  </div>
  <table class="todolist">
    <?=$html_int?>
  </table>

  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start();
  ?>
    <div class="Sidebar">
      <?$sel="extensions";include("../sidebar.php");?>
      <h1><?=T_("Informations")?></h1>
          <p><?=T_("On the left you find all the users that can use the pbx. For each item, you can see the status of the extension. The possible status are:<br><br>")?></p>
           <ul>
            <li><img src="<?=$relBasePath?>/public/img/online.gif" align="left"/><strong><?=T_("Online")?>: </strong><?=T_("The user is currently connected")?></li>
            <li><img src="<?=$relBasePath?>/public/img/offline.gif" align="left"/><strong><?=T_("Offline")?>: </strong><?=T_("The user is offline")?></li>
            <li><img src="<?=$relBasePath?>/public/img/unknown.gif" align="left"/><strong><?=T_("Unknown")?>: </strong><?=T_("The status is unknonwn")?></li>
           </ul>
        </div>
       <div style="text-align: center"><img src="<?=$relBasePath?>public/img/book.jpg" alt="Rubrica" align="center"/></div>
    </div>
  <?
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================
  $smarty->assign("section", "contacts");
  $smarty->assign("subsection", "");
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('main.tpl');
?>
